<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * JobeetJob filter form base class.
 *
 * @package    jobeet
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 13459 2008-11-28 14:48:12Z fabien $
 */
class BaseJobeetJobFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'category_id'               => new sfWidgetFormPropelChoice(array('model' => 'JobeetCategory', 'add_empty' => true)),
      'type'                      => new sfWidgetFormFilterInput(),
      'company'                   => new sfWidgetFormFilterInput(),
      'logo'                      => new sfWidgetFormFilterInput(),
      'url'                       => new sfWidgetFormFilterInput(),
      'position'                  => new sfWidgetFormFilterInput(),
      'location'                  => new sfWidgetFormFilterInput(),
      'description'               => new sfWidgetFormFilterInput(),
      'how_to_apply'              => new sfWidgetFormFilterInput(),
      'token'                     => new sfWidgetFormFilterInput(),
      'is_public'                 => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'is_activated'              => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'email'                     => new sfWidgetFormFilterInput(),
      'expires_at'                => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'created_at'                => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'updated_at'                => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'jobeet_job_affiliate_list' => new sfWidgetFormPropelChoice(array('model' => 'JobeetAffiliate', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'category_id'               => new sfValidatorPropelChoice(array('required' => false, 'model' => 'JobeetCategory', 'column' => 'id')),
      'type'                      => new sfValidatorPass(array('required' => false)),
      'company'                   => new sfValidatorPass(array('required' => false)),
      'logo'                      => new sfValidatorPass(array('required' => false)),
      'url'                       => new sfValidatorPass(array('required' => false)),
      'position'                  => new sfValidatorPass(array('required' => false)),
      'location'                  => new sfValidatorPass(array('required' => false)),
      'description'               => new sfValidatorPass(array('required' => false)),
      'how_to_apply'              => new sfValidatorPass(array('required' => false)),
      'token'                     => new sfValidatorPass(array('required' => false)),
      'is_public'                 => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_activated'              => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'email'                     => new sfValidatorPass(array('required' => false)),
      'expires_at'                => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'created_at'                => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'updated_at'                => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'jobeet_job_affiliate_list' => new sfValidatorPropelChoice(array('model' => 'JobeetAffiliate', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('jobeet_job_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addJobeetJobAffiliateListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(JobeetJobAffiliatePeer::JOB_ID, JobeetJobPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(JobeetJobAffiliatePeer::AFFILIATE_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(JobeetJobAffiliatePeer::AFFILIATE_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'JobeetJob';
  }

  public function getFields()
  {
    return array(
      'id'                        => 'Number',
      'category_id'               => 'ForeignKey',
      'type'                      => 'Text',
      'company'                   => 'Text',
      'logo'                      => 'Text',
      'url'                       => 'Text',
      'position'                  => 'Text',
      'location'                  => 'Text',
      'description'               => 'Text',
      'how_to_apply'              => 'Text',
      'token'                     => 'Text',
      'is_public'                 => 'Boolean',
      'is_activated'              => 'Boolean',
      'email'                     => 'Text',
      'expires_at'                => 'Date',
      'created_at'                => 'Date',
      'updated_at'                => 'Date',
      'jobeet_job_affiliate_list' => 'ManyKey',
    );
  }
}
